﻿using System;
using System.Windows.Forms;
using YArchitech.HCLoad.Utils;

namespace YArchitech.HCLoad.Controls
{
	public class HcNumberTextBox : TextBox
	{
		protected override void WndProc(ref Message m)
		{
			int msg = m.Msg;
			if (msg != 258)
			{
				if (msg != 770)
				{
					base.WndProc(ref m);
				}
				else
				{
					IDataObject dataObject = Clipboard.GetDataObject();
					if (dataObject.GetDataPresent(DataFormats.Text) && HcUtils.IsNum((string)dataObject.GetData(DataFormats.Text)))
					{
						base.WndProc(ref m);
						return;
					}
					m.Result = (IntPtr)0;
					return;
				}
			}
			else
			{
				Console.WriteLine(m.WParam);
				bool flag = (int)m.WParam == 45;
				bool flag2 = (int)m.WParam >= 48 && (int)m.WParam <= 57;
				bool flag3 = (int)m.WParam == 8;
				bool flag4 = (int)m.WParam == 46;
				bool flag5 = (int)m.WParam == 24 || (int)m.WParam == 22 || (int)m.WParam == 26 || (int)m.WParam == 3;
				if (flag2 || flag3 || flag5)
				{
					base.WndProc(ref m);
				}
				if (flag)
				{
					if (base.SelectionStart == 0)
					{
						base.WndProc(ref m);
						return;
					}
				}
				else
				{
					if (flag4 && this.Text.IndexOf(".") < 0)
					{
						base.WndProc(ref m);
					}
					if ((int)m.WParam == 1)
					{
						base.SelectAll();
						return;
					}
				}
			}
		}

		public double Value
		{
			get
			{
				return HcConvert.ToDouble(this.Text);
			}
			set
			{
				this.Text = value.ToString();
			}
		}

		public const int WM_CONTEXTMENU = 123;

		public const int WM_CHAR = 258;

		public const int WM_CUT = 768;

		public const int WM_COPY = 769;

		public const int WM_PASTE = 770;

		public const int WM_CLEAR = 771;

		public const int WM_UNDO = 772;
	}
}
